retire strsub, gstrsub. (#862)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Fri, 11 Mar 2022 20:52:01 +0000 (13:52 -0700)
committerGitHub <noreply@github.com>
Fri, 11 Mar 2022 20:52:01 +0000 (13:52 -0700)
defs.h
explorist_ini.cc
util.cc

diff --git a/defs.h b/defs.h
index b08b45f8aa3fcfcf85d092c21d86315d6ff11778..662ba59d5020aca8d77789b9d269cdf07cd59f80 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -1061,9 +1061,6 @@ inline int case_ignore_strncmp(const QString& s1, const QString& s2, int n)
 
 int str_match(const char* str, const char* match);
 
-char* strsub(const char* s, const char* search, const char* replace);
-char* gstrsub(const char* s, const char* search, const char* replace);
-
 void rtrim(char* s);
 char* lrtrim(char* buff);
 int xasprintf(char** strp, const char* fmt, ...) PRINTFLIKE(2, 3);
index 72a9df9c556a4291c8eca533e834caae5bf2efdd..e9eafdb3531dc64ab7238420079c974ddbaad3fa 100644 (file)
@@ -30,20 +30,20 @@ explorist_ini_try(const char* path)
   info->track_path = nullptr;
   info->waypoint_path = nullptr;
 
-  char* s = xstrdup(inifile_readstr(inifile,  "UGDS", "WpFolder"));
-  if (s) {
-    s = gstrsub(s, "\\", "/");
-    xasprintf(&info->waypoint_path, "%s/%s", path, s);
+  QString s = inifile_readstr(inifile,  "UGDS", "WpFolder");
+  if (!s.isNull()) {
+    s.replace('\\', '/');
+    xasprintf(&info->waypoint_path, "%s/%s", path, CSTR(s));
   }
-  s = xstrdup(inifile_readstr(inifile,  "UGDS", "GcFolder"));
-  if (s) {
-    s = gstrsub(s, "\\", "/");
-    xasprintf(&info->geo_path, "%s/%s", path, s);
+  s = inifile_readstr(inifile,  "UGDS", "GcFolder");
+  if (!s.isNull()) {
+    s.replace('\\', '/');
+    xasprintf(&info->geo_path, "%s/%s", path, CSTR(s));
   }
-  s = xstrdup(inifile_readstr(inifile,  "UGDS", "TrkFolder"));
-  if (s) {
-    s = gstrsub(s, "\\", "/");
-    xasprintf(&info->track_path, "%s/%s", path, s);
+  s = inifile_readstr(inifile,  "UGDS", "TrkFolder");
+  if (!s.isNull()) {
+    s.replace('\\', '/');
+    xasprintf(&info->track_path, "%s/%s", path, CSTR(s));
   }
 
   inifile_done(inifile);
diff --git a/util.cc b/util.cc
index a329463c7eabee3b8ac99d1372968b178162cfcc..9007b68e77a74c2386c9b220e45caa65621ec49d 100644 (file)
--- a/util.cc
+++ b/util.cc
@@ -935,72 +935,6 @@ double degrees2ddmm(double deg_val)
   return (deg * 100.0) + ((deg_val - deg) * 60.0);
 }
 
-/*
- * replace a single occurrence of "search" in  "s" with "replace".
- * Returns an allocated copy if substitution was made, otherwise returns NULL.
- * Doesn't try to make an optimally sized dest buffer.
- */
-char*
-strsub(const char* s, const char* search, const char* replace)
-{
-  int len = strlen(s);
-  int slen = strlen(search);
-  int rlen = strlen(replace);
-
-  const char* p = strstr(s, search);
-  if (!slen || !p) {
-    return nullptr;
-  }
-
-  char* d = (char*) xmalloc(len + rlen + 1);
-
-  /* Copy first part */
-  len = p - s;
-  memcpy(d, s, len);
-  d[len] = 0;
-
-  /* Copy replacement */
-  strcat(d, replace);
-
-  /* Copy last part */
-  strcat(d, p + slen);
-  return d;
-}
-
-/*
- *  As strsub, but do it globally.
- */
-char*
-gstrsub(const char* s, const char* search, const char* replace)
-{
-  int ooffs = 0;
-  const char* c;
-  const char* src = s;
-  int olen = strlen(src);
-  int slen = strlen(search);
-  int rlen = strlen(replace);
-
-  char* o = (char*) xmalloc(olen + 1);
-
-  while ((c = strstr(src, search))) {
-    olen += (rlen - slen);
-    o = (char*) xrealloc(o, olen + 1);
-    memcpy(o + ooffs, src, c - src);
-    ooffs += (c - src);
-    src = c + slen;
-    if (rlen) {
-      memcpy(o + ooffs, replace, rlen);
-      ooffs += rlen;
-    }
-  }
-
-  if (ooffs < olen) {
-    memcpy(o + ooffs, src, olen - ooffs);
-  }
-  o[olen] = '\0';
-  return o;
-}
-
 /*
  *
  */